/**
 * 扑克牌
 */
class Poker_public {
	public id: number;//每张牌id
	public color: number;//每张牌的花色，黑红梅方 3 2 1 0
	public value: number;//牌的值，1-13

	public static chessArray: Array<Poker_public> = new Array<Poker_public>();
	//用ID生成对象
	public constructor(ID: number) {
		if (ID > 0 && ID <= 13) {
			this.id = ID;
			this.color = 0;
			this.value = ID;
		}

		if (ID > 16 && ID <= 29) {
			this.id = ID;
			this.color = 1;
			this.value = ID - 16;
		}
		if (ID > 32 && ID <= 45) {
			this.id = ID;
			this.color = 2;
			this.value = ID - 32;
		}
		if (ID > 48 && ID <= 61) {
			this.id = ID;
			this.color = 3;
			this.value = ID - 48;
		}
		if (ID == 78) {
			this.id = ID;
			this.color = 4;
			this.value = 14;
		}
		if (ID == 79) {
			this.id = ID;
			this.color = 4;
			this.value = 15;
		}
	}
	public getColor() {
		return this.color;
	}
	public setColor(color) {
		this.color = color;
	}
	public getValue() {
		return this.value;
	}
	public setValue(value) {
		this.value = value;
	}

	//后端ID数组在前端转化为对象数组
	public static idChangeObject(list: Array<number>): Array<Poker_public> {
		let newList: Array<Poker_public> = [];
		for (let i in list) {
			newList[newList.length] = Poker_public.chessArray[list[i]];
		}
		return newList;
	}
	//排序
	public static sort(list: Array<Poker_public>): Array<Poker_public> {
		var temp: any = "";
		for (var i = list.length - 1; i > 0; --i) {
			for (var j = 0; j < i; j++) {
				if (list[j + 1].value > list[j].value) {
					temp = list[j];
					list[j] = list[j + 1];
					list[j + 1] = temp;
				} else if (list[j + 1].value == list[j].value && list[j + 1].color > list[j].color) {
					temp = list[j];
					list[j] = list[j + 1];
					list[j + 1] = temp;
				}
			}
		}

		// let Newlist: Array<Poker_public> = [];
		// for (let i = list.length - 1; i >= 0; i--) {
		// 	if (list[i].value == 1 || list[i].value == 2 || list[i].value == 14 || list[i].value == 15) {
		// 		Newlist.unshift(list[i]);
		// 		list.splice(i, 1)
		// 	}
		// }
		// if (Newlist.length == 0) {
		// 	return list;
		// }
		// for (let i = 0; i < list.length; i++) {
		// 	Newlist.push(list[i]);
		// }
		return list;
	}
	public static init() {
		Poker_public.chessArray.splice(0, Poker_public.chessArray.length);
		for (var id = 1; id <= 13; id++) {//一共54张牌
			var poker: Poker_public = new Poker_public(id);
			Poker_public.chessArray[id] = poker;
		}
		for (var id = 17; id <= 29; id++) {//一共54张牌
			var poker: Poker_public = new Poker_public(id);
			Poker_public.chessArray[id] = poker;
		}
		for (var id = 33; id <= 45; id++) {
			var poker: Poker_public = new Poker_public(id);
			Poker_public.chessArray[id] = poker;
		}
		for (var id = 49; id <= 61; id++) {
			var poker: Poker_public = new Poker_public(id);
			Poker_public.chessArray[id] = poker;
		}
		for (var id = 78; id <= 79; id++) {
			var poker: Poker_public = new Poker_public(id);
			Poker_public.chessArray[id] = poker;
		}
	}
}